<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试未答题目功能</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .test-section {
            margin: 20px 0;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        button {
            background: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background: #0056b3;
        }
        .result {
            margin-top: 15px;
            padding: 10px;
            background: #f8f9fa;
            border-radius: 5px;
            white-space: pre-wrap;
        }
        .error {
            background: #f8d7da;
            color: #721c24;
        }
        .success {
            background: #d4edda;
            color: #155724;
        }
    </style>
</head>
<body>
    <h1>测试未答题目功能</h1>
    
    <div class="test-section">
        <h2>测试场景：包含未答题目的作业</h2>
        <p>模拟OCR识别结果包含一些未答题目的情况</p>
        <button onclick="testUnansweredQuestions()">测试未答题目处理</button>
        <div id="result1" class="result" style="display: none;"></div>
    </div>

    <div class="test-section">
        <h2>测试场景：所有题目都有答案</h2>
        <p>模拟OCR识别结果所有题目都有学生答案的情况</p>
        <button onclick="testAllAnswered()">测试全部答题处理</button>
        <div id="result2" class="result" style="display: none;"></div>
    </div>

    <script>
        const API_BASE = 'http://localhost:8898/ai';

        async function testUnansweredQuestions() {
            const resultDiv = document.getElementById('result1');
            resultDiv.style.display = 'block';
            resultDiv.textContent = '正在测试...';
            resultDiv.className = 'result';

            try {
                const testData = {
                    ocrText: `
                        一、填空题
                        1. 3 + 5 = ___
                        2. 10 - 4 = 6
                        3. 2 × 3 = ___
                        
                        二、口算题
                        4. 8 + 2 = ___
                        5. 15 - 7 = 8
                        6. 4 × 5 = ___
                    `,
                    subject: '数学',
                    gradingCriteria: '小学二年级数学作业'
                };

                const response = await fetch(`${API_BASE}/grade`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify(testData)
                });

                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }

                const result = await response.json();
                
                resultDiv.className = 'result success';
                resultDiv.textContent = `测试成功！\n\n返回结果：\n${JSON.stringify(result, null, 2)}`;
                
                // 检查是否包含未答题目信息
                if (result.unansweredQuestions && result.unansweredQuestions.length > 0) {
                    resultDiv.textContent += `\n\n✅ 成功检测到 ${result.unansweredQuestions.length} 个未答题目`;
                } else {
                    resultDiv.textContent += `\n\n⚠️ 未检测到未答题目信息`;
                }

            } catch (error) {
                resultDiv.className = 'result error';
                resultDiv.textContent = `测试失败：${error.message}`;
            }
        }

        async function testAllAnswered() {
            const resultDiv = document.getElementById('result2');
            resultDiv.style.display = 'block';
            resultDiv.textContent = '正在测试...';
            resultDiv.className = 'result';

            try {
                const testData = {
                    ocrText: `
                        一、填空题
                        1. 3 + 5 = 8
                        2. 10 - 4 = 6
                        3. 2 × 3 = 6
                        
                        二、口算题
                        4. 8 + 2 = 10
                        5. 15 - 7 = 8
                        6. 4 × 5 = 20
                    `,
                    subject: '数学',
                    gradingCriteria: '小学二年级数学作业'
                };

                const response = await fetch(`${API_BASE}/grade`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify(testData)
                });

                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }

                const result = await response.json();
                
                resultDiv.className = 'result success';
                resultDiv.textContent = `测试成功！\n\n返回结果：\n${JSON.stringify(result, null, 2)}`;
                
                // 检查未答题目信息
                if (result.unansweredQuestions && result.unansweredQuestions.length === 0) {
                    resultDiv.textContent += `\n\n✅ 正确：没有未答题目`;
                } else if (result.unansweredQuestions && result.unansweredQuestions.length > 0) {
                    resultDiv.textContent += `\n\n⚠️ 意外：检测到 ${result.unansweredQuestions.length} 个未答题目`;
                } else {
                    resultDiv.textContent += `\n\n⚠️ 未返回未答题目信息字段`;
                }

            } catch (error) {
                resultDiv.className = 'result error';
                resultDiv.textContent = `测试失败：${error.message}`;
            }
        }
    </script>
</body>
</html>